package com.terry.trace.test.controller;

import com.alibaba.ttl.TtlRunnable;
import com.terry.trace.core.LogTagContext;
import com.terry.trace.core.TraceLogger;
import com.terry.trace.plugin.LogAround;
import com.terry.trace.test.service.LogService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
public class LogController {

    private static final TraceLogger LOGGER = TraceLogger.getLogger(LogController.class);
    final ExecutorService executorService = Executors.newFixedThreadPool(10);

    @Resource
    private LogService logService;

    //@LogAround
    @RequestMapping("say")
    public String say(String name) {
        /*final TtlRunnable ttlRunnable = TtlRunnable.get(new Runnable() {
            @Override
            public void run() {
                LOGGER.info("=say name = [{}]", Thread.currentThread().getName());
                LogTagContext.remove();
            }
        });

        executorService.execute(ttlRunnable);*/
        LOGGER.info("say name = [{}]", name);
        logService.log(name);
        //LOGGER.error("say name = [{}]", name, new RuntimeException("aaa"));
        return "success";
    }
}
